home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Linux Cubed Series 8: LINUX Games
/
Linux Cubed Series 8 - LINUX Games.iso
/
games
/
x11
/
rpg
/
crossfir.92
/
crossfir
/
crossfire-0.92.5
/
common
/
sqrt.c
< prev
next >
Wrap
Text File
|
1996-07-24
|
572b
|
30 lines
/*
* static char *rcsid_sqrt_c =
* "$Id: sqrt.c,v 1.11 1994/03/29 08:28:26 master Exp $";
*/
/*
* Based on (n+1)^2 = n^2 + 2n + 1
* given that 1^2 = 1, then
* 2^2 = 1 + (2 + 1) = 1 + 3 = 4
* 3^2 = 4 + (4 + 1) = 4 + 5 = 1 + 3 + 5 = 9
* 4^2 = 9 + (6 + 1) = 9 + 7 = 1 + 3 + 5 + 7 = 16
* ...
* In other words, a square number can be express as the sum of the
* series n^2 = 1 + 3 + ... + (2n-1)
*/
int
isqrt(n)
int n;
{
int result, sum, prev;
result = 0;
prev = sum = 1;
while (sum <= n) {
prev += 2;
sum += prev;
++result;
}
return result;
}